<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>科研成果</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,LightYearAdmin,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="Light Year Admin V4是一个后台管理系统的HTML模板，基于Bootstrap v4.4.1。">
    <meta name="author" content="yinqi">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="/static/js/jquery-confirm/jquery-confirm.min.css" rel="stylesheet">
    <link href="/static/css/animate.min.css" rel="stylesheet">
    <link href="/static/css/style.min.css" rel="stylesheet">
    <style>
        .avatar{
            width: 30px;
            height: 30px;
        }
    </style>
</head>

<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-toolbar d-flex flex-column flex-md-row">
                    <div class="toolbar-btn-action">
                        <a class="btn btn-primary m-r-5" href="{:url('index/file/addFile')}"><i class="mdi mdi-plus"></i> 新增科研成果</a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>主题</th>
                                <th>描述</th>
                                <th>附件文件名</th>
                                <th>上传时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach $files as $file}
                            <tr>
                                <td width="100">{$file['id']}</td>
                                <td width="200">{$file['title']}</td>
                                <td style="max-width: 600px;overflow: hidden;text-overflow:ellipsis">
                                    <textarea class="form-control"  readonly>{$file['describe']}</textarea>
                                </td>
                                <td width="200">{$file['filename']}</td>
                                <td width="200"> {:date("Y-m-d h:i:s",$file['create_time'])}</td>
                                <td width="200">
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-danger" onclick="delFile({$file['id']})">删除科研成果</button>
                                        <button class="btn btn-success" onclick="downloadFile('{$file['path']}')">下载附件</button>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                        {if  count($files)==0}
                        <p>暂无科研成果</p>
                        {/if}
                    </div>
                    {$files|raw}

                </div>
            </div>
        </div>
    </div>

</div>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/popper.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/lyear-loading.js"></script>
<script type="text/javascript" src="/static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/static/js/jquery-confirm/jquery-confirm.min.js"></script>
<script type="text/javascript" src="/static/js/main.min.js"></script>
<script type="text/javascript" src="/static/js/msg.js"></script>
<script type="text/javascript">
    function delFile(id){
        $.confirm({
            title: '',
            content:'确认要执行该操作吗？',
            type: 'orange',
            typeAnimated: true,
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-blue',
                    action: function() {
                        action(id);
                    }
                },
                cancel: {
                    text: '取消',
                    action: function() {}
                }
            }
        });
    }
    function action(id){
        $.ajax({
            url: '/index/file/delFile',
            data:{id},
            method:"POST",
            dataType:"json",
            success:function (res){
                if(res.code){
                    msgShow.success(res.msg);
                    setTimeout(()=>{
                        location.reload();
                    },1000)
                }else{
                    msgShow.error(res.msg)
                }
            }
        })
    }
    function downloadFile(path){
        window.open(path);
    }

</script>
</body>
</html>